package com.ilxqx.framework.system.service.impl;

import com.ilxqx.framework.system.entity.SysUser;
import com.ilxqx.framework.system.form.search.SysUserSearchForm;
import com.ilxqx.framework.system.repository.SysUserRepository;
import com.ilxqx.framework.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 用户服务实现类
 * @author venus
 */
@Service
public class SysUserServiceImpl extends AbstractSearchableServiceImpl<SysUser, Long, SysUserSearchForm> implements SysUserService {

    private final SysUserRepository sysUserRepository;

    @Autowired
    public SysUserServiceImpl(SysUserRepository sysUserRepository) {
        super(sysUserRepository);
        this.sysUserRepository = sysUserRepository;
    }

    /**
     * 创建空的或者带有默认值的实体对象
     *
     * @return 实体对象
     */
    @Override
    public SysUser create() {
        return new SysUser();
    }

    /**
     * 根据账号，查询系统用户
     *
     * @param account 账号
     * @return 系统用户Optional对象
     */
    @Override
    public Optional<SysUser> getByAccount(String account) {
        return sysUserRepository.getByAccount(account);
    }

    /**
     * 判断账号是否存在
     *
     * @param account 账号
     * @return 存在的用户
     */
    @Override
    public SysUser accountExists(String account) {
        return this.sysUserRepository.getByAccount(account).orElse(null);
    }

}
